home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #11
/
Amiga Plus CD - 2004 - No. 11.iso
/
AmiSoft
/
Dev
/
misc
/
LOCCounter.lha
/
LOCCounter
/
src
/
Main.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2004-08-18
|
3KB
|
129 lines
/****************************************************************************
*
* $RCSfile: Main.cpp $
* $Revision: 2.15 $
* $Date: 2004/08/18 21:48:32 $
* $Author: ssolie $
*
*****************************************************************************
*
* Copyright (c) 2004 Steven Solie. All Rights Reserved.
*
*****************************************************************************
*
* Main.cpp -- C++ LOC Counter
*
* This program counts the lines of code (LOC) in C++ (or C) source code.
* The parser is very simple and relies on the "C++ Coding Standard" and
* the "C++ LOC Standard" to produce a logical LOC count.
*/
#include "Main.h"
#include "ArgParser.h"
#include "PatternMatch.h"
#include "SourceCode.h"
#include "Tally.h"
#include "FileCount.h"
#include <proto/dos.h>
#include <ios>
#include <list>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
namespace {
const char* VERSTAG = "$VER: loc 3.0 (18.8.04)";
const char* APPNAME = "loc";
const char* TEMPLATE = "FILE/M/A,TOTAL/S,DIFF=DIFFERENCE/S,QUICK/S";
const char* ARG_FILE = "FILE";
const char* ARG_TOTAL = "TOTAL";
const char* ARG_DIFF = "DIFF";
const char* ARG_QUICK = "QUICK";
};
/*
* main -- Main entry point
*
* This is the main entry point for the program. Returns a valid DOS
* return code indicating success or failure.
*/
int main()
{
extern struct WBStartup* __WBenchMsg;
if ( __WBenchMsg != 0 ) {
return RETURN_FAIL;
}
std::ios::sync_with_stdio(false);
ArgParser parser;
if ( parser.parse(TEMPLATE) == false ) {
IDOS->PrintFault(IDOS->IoErr(), const_cast<STRPTR>(APPNAME));
return RETURN_FAIL;
}
const bool show_diff = parser.getBoolean(ARG_DIFF, false);
const bool show_total = parser.getBoolean(ARG_TOTAL, false);
const bool quick = parser.getBoolean(ARG_QUICK, false);
const BPTR out = IDOS->Output();
// Count the LOC and tally the results.
int32 result = RETURN_OK;
try {
PatternMatch match;
std::list< boost::shared_ptr<FileCount> > file_counts;
Tally tally(show_diff);
char* pattern = parser.firstString(ARG_FILE);
while ( pattern != 0 ) {
const char* file_name = match.firstFile(pattern);
while ( file_name != 0 ) {
boost::shared_ptr<FileCount> file_count(new FileCount(file_name, show_diff));
file_counts.push_back(file_count);
boost::scoped_ptr<SourceCode> source(new SourceCode(*file_count));
source->load();
source->count();
tally.addFile(*file_count);
file_name = match.nextFile();
}
pattern = parser.nextString();
}
if ( quick ) {
tally.printQuick(out);
}
else {
if ( show_total ) {
tally.printTotal(out);
}
else {
tally.print(out);
}
}
}
catch ( std::bad_alloc ) {
IDOS->SetIoErr(ERROR_NO_FREE_STORE);
IDOS->PrintFault(ERROR_NO_FREE_STORE, const_cast<STRPTR>(APPNAME));
result = RETURN_FAIL;
}
catch ( dos_error ) {
IDOS->PrintFault(IDOS->IoErr(), const_cast<STRPTR>(APPNAME));
result = RETURN_ERROR;
}
catch ( ... ) {
result = RETURN_FAIL;
}
return result;
}